package com.rslai.base.tool.servertest.casefilter;

import com.rslai.base.tool.servertest.model.TestCase;
import com.rslai.base.tool.servertest.model.TestSuite;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.StringUtils;

public class CaseIDsFilter implements CaseFilter {
    private List<String> ids;

    public CaseIDsFilter(String ids) {
        if (StringUtils.isBlank(ids))
            this.ids = Collections.EMPTY_LIST;
        else
            this.ids = Arrays.asList(StringUtils.split(ids, ","));
    }

    public void filter(TestSuite testSuite) {
        if (this.ids.isEmpty()) return;
        List needRerun = new ArrayList();
        for (TestCase testCase : testSuite.getTestCases()) {
            if (this.ids.contains(testCase.getId())) {
                needRerun.add(testCase);
            }
        }
        testSuite.setTestCases(needRerun);
    }
}
